<?php
namespace common\models\goods;

use Yii;
use yii\db\ActiveRecord;
use yii\behaviors\TimestampBehavior;
use common\enums\StatusEnum;
use common\helpers\RegularHelper;

class Tag extends ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%goods_tag}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['member_id', 'store_id','sort', 'status', 'created_at', 'updated_at'], 'integer'],
            [['name'], 'string', 'max' => 20],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'member_id' => '账号ID',
            'store_id' => '店铺ID',
            'name' => '分组名称',
            'sort' => '排序',
            'status' => '状态',
            'created_at' => '创建时间',
            'updated_at' => '修改时间',
        ];
    }

    /**
     * 场景
     *
     * @return array
     */
    public function scenarios()
    {
        return [
//            'create' => [''],
//            'backendCreate' => ['username', 'password_hash'],
            'default' => array_keys($this->attributeLabels()),
        ];
    }

//    /**
//     * 关联第三方绑定
//     */
//    public function getAuth()
//    {
//        $this->hasMany(MemberAuth::class, ['member_id' => 'id'])->where(['status' => StatusEnum::ENABLED]);
//    }


    /**
     * @return array
     */
    public function behaviors()
    {
        return [
            [
                'class' => TimestampBehavior::class,
                'attributes' => [
                    ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'],
                    ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'],
                ],
            ],
        ];
    }
}
